<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>专家方案筛选</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		#searchForm .ui-select{
			display:inline-block;vertical-align: middle;width:300px;
		}
	 </style>
	
</head>
<body>
	<div data-role="navbar">
		<ul>
			<li><a href="#"  class="ui-btn-active">专家方案筛选</a></li>
			<li><a class="leave-page" href="${ctx}/expert/customerExam/customerNotActive">不活跃客户开发</a></li>
		</ul>
	</div>
	<div class="icon-buttons">
		<a data-role="button" class="leave-page" data-inline="true" data-icon="back" data-iconpos="notext"  href="${ctx}">返回</a>
	</div>
	<tags:message content="${message}"/>
	<div class="form-input"> 
	<form id="searchForm" action="#" method="post" class="middleCls">
		<label for="solutionId">选择方案:</label>
		<select id="solutionId" name="solutionId">
		   <c:if test="${empty fns:getSolutionByStore()}">
		  	 <option value='-1'>无方案</option>
		   </c:if>
		   <c:if test="${not empty fns:getSolutionByStore()}">
			  <c:forEach var="map" items="${fns:getSolutionByStore()}">   
			 	<option value='${map.key}' ${map.key == session_solution ? 'selected' : '' }>${map.value}</option>
			  </c:forEach>   
		   </c:if>
		</select> 
		<input id="btnSubmit" data-inline="true" onclick="searchList()" type="button" value="查询"/>
		<c:if test="${not empty customerList}">
			<input id="sendSms" data-inline="true" onclick="sendSmsToCustomers()" type="button" value="发送短信"/>
		</c:if>
	</form>
	<c:if test="${not empty customerList}">
	<label class="middleCls"><h3>符合条件顾客列表</h3></label>
	<table id="contentTable" data-role="table" class="ui-responsive table-stroke">
		<thead><tr><th>顾客姓名</th><th>备注名</th><th>电话</th><th>操作</th></tr></thead>
		<tbody>
			<c:forEach items="${customerList}" var="customer">
				<tr id="${customer.id}" class="customerTr">
					<td>${customer.name}</td>
					<td>${customer.nickname}</td>
					<td>${customer.mobile}</td>
					<td class="operateTD" id="${customer.id}">
						<input type="button" data-inline="true" data-iconpos="notext" data-icon="delete" value="删除"/>
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	</c:if>
	</div>
	<script type="text/javascript">
		$(document).ready(function() {	
			$("#contentTable tbody tr").click(function(e){
				sessionStorage.target = "customerSearch";
				window.location.href = "${ctx}/base/customer/detail?id=" + this.id;
			});
			$(".operateTD").click(function(){
				deleteCustomer(this.id);
			});
			//离开本模块时,清除使用过的session
			$(".leave-page").click(function(){
				var target = this.href;
				var url = "${ctx}/cleanSession?sessionKeys=session_solution,session_fliter_customer";
				var backFun = function(){
					window.location.href = target;
		 		};
		 		syncToServer(url, backFun);
				return false;
			});
		});
		var findCustomers = "";
		function searchList() {
			var solutionId = $("#solutionId").val();
			if(!solutionId) {
				showTip('请先选择方案！');
				return;
			}
			var url = "${ctx}/expert/customerExam/getCustomers?solution_id=" + solutionId;
			window.location.href = url;
		}
		function deleteCustomer(customerId){
			if (!customerId) {
				return;
			}
			var url = "${ctx}/expert/customerExam/deleteCustomer?target=solution&customerId=" + customerId;
			var fun = function(){
				$("#" + customerId).attr("class",'hide');
				syncToServer(url);
			};
			global.confirm("确定移除此用户？",fun);
			this.event.stopPropagation();
		}
		function sendSmsToCustomers(){
			var tr = $(".customerTr");
			if (!tr || tr.length == 0) {
				showTip('没有符合用户！');
    		 	return;
				}
			var ids = ''; 
			if (tr && tr.length > 0) {
				for(var i = 0, len = tr.length; i < len; i ++){
					var c = tr[i];
	        		ids +=  c.id + ',';
				}
			}
       	  	if (ids){
				ids = ids.substring(0, ids.length - 1);
           	  	}
			var url = "${ctx}/sms/sendStoreGroupToCustomer/customerList?customerIds=" + ids + "&target=customer";
			window.location.href = url;
		}
	</script>
</body>
</html>
